import { CHANGE_INPUT_VALUE, ADD_TODO_ITEM, REDUCE_TODO_ITEM, CHANGE_LIST_INFO } from './actionTypes'


const defaultState = {
  list: [1, 22, 34],
  inputValue: 789
}

export default (state = defaultState, action) => {
  const newState = JSON.parse(JSON.stringify(state))
  switch (action.type) {
    case CHANGE_INPUT_VALUE:
      newState.inputValue = action.value
      return newState
    case ADD_TODO_ITEM:
      newState.list.push(newState.inputValue)
      return newState
    case REDUCE_TODO_ITEM:
      newState.list.splice(action.index,1)
      return newState
    case CHANGE_LIST_INFO:
      newState.list = action.data
      return newState
    default:
      return state
  }
}